<template>
  <div>
    <el-table :data="devices" style="width: 100%; height: 100%; font-size: 14px">
      <el-table-column align="center" label="设备类型">
        <template #default="scope">
          <dict-tag :options="sys_device_type" :value="scope.row.deviceType" />
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" align="center" label="主机" prop="ipaddr" />
      <el-table-column :show-overflow-tooltip="true" align="center" label="登录地点" prop="loginLocation" />
      <el-table-column :show-overflow-tooltip="true" align="center" label="操作系统" prop="os" />
      <el-table-column :show-overflow-tooltip="true" align="center" label="浏览器" prop="browser" />
      <el-table-column align="center" label="登录时间" prop="loginTime" width="180">
        <template #default="scope">
          <span>{{ proxy.parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template #default="scope">
          <el-tooltip content="删除" placement="top">
            <el-button icon="Delete" link type="primary" @click="handldDelOnline(scope.row)"> </el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" name="Online" setup>
// import { delOnline } from '@/api/monitor/online';
import {propTypes} from '@/utils/propTypes';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_device_type } = toRefs<any>(proxy?.useDict('sys_device_type'));

const props = defineProps({
  devices: propTypes.any.isRequired
});
const devices = computed(() => props.devices);

/** 删除按钮操作 */
const handldDelOnline = (row: any) => {
  ElMessageBox.confirm('删除设备后，在该设备登录需要重新进行验证')
    .then(() => {
      return delOnline(row.tokenId);
    })
    .then((res: any) => {
      if (res.code === 200) {
        proxy?.$modal.msgSuccess('删除成功');
        proxy?.$tab.refreshPage();
      } else {
        proxy?.$modal.msgError(res.msg);
      }
    })
    .catch(() => {});
};
</script>
